package com.ethan.staticproxy;

import com.google.common.base.Stopwatch;

import java.util.concurrent.TimeUnit;

/**
 * @author ethan
 * create 2018-08-02 上午10:47
 * desc 代理类,实现了代理接口
 **/
public class ProxySubject implements Subject{
    //代理类持有一个委托类的对象引用
    private Subject delegate;

    public ProxySubject(Subject subject){
        this.delegate = subject;
    }

    @Override
    public void dealTask(String taskName) {
        Stopwatch stopwatch = Stopwatch.createStarted();
        delegate.dealTask(taskName);
        System.out.println("执行任务耗时"+stopwatch.elapsed(TimeUnit.MILLISECONDS));
    }
}
